import CryptoJS from 'crypto-js'
import top from './MD5'

const ryutil = {
  /**
   * 加密
   *
   * @param word
   * @returns {*}
   */
  encryptaes: function (word, key) {
    // var key = CryptoJS.enc.Utf8.parse("jsruiyinv5876666");
    var key = CryptoJS.enc.Utf8.parse(key)
    var srcs = CryptoJS.enc.Utf8.parse(word)
    var encrypted = CryptoJS.AES.encrypt(srcs, key, {
      mode: CryptoJS.mode.ECB,
      padding: CryptoJS.pad.Pkcs7,
    })
    return encrypted.toString()
  },
  /**
   * 使用MD5加密
   *
   */
  encrypt: function (needPass) {
    return top.hex_md5(needPass)
  },
  /**
   * 解密
   *
   * @param word
   * @returns {*}
   */
  decryptaes: function (word, key) {
    // var key = CryptoJS.enc.Utf8.parse("jsruiyinv5876666");
    var key = CryptoJS.enc.Utf8.parse(key)
    var decrypt = CryptoJS.AES.decrypt(word, key, {
      mode: CryptoJS.mode.ECB,
      padding: CryptoJS.pad.Pkcs7,
    })
    return CryptoJS.enc.Utf8.stringify(decrypt).toString()
  },
}

export default ryutil
